const Player = require('@zhzq/simple-audio-player')
const { convertTime } = require('./src/util')
const p = new Player
if(process.argv.length<3){
  throw new Error('usage: node player <url>')
}
p.prepare(process.argv[2]).then(() => {
  p.play(f => {
    process.stdout.write(`\r\x1b[K\x1b[3${Math.floor(Math.random()*7+1)}m${convertTime(f.currentPos)}/${convertTime(f.duration)}   ${
    (function () {
      const d = Math.round(f.currentPos * 50 / f.duration)
      return `[${'#'.repeat(d)}${'-'.repeat(50 - d)}]`
    }())}\x1b[0m`)
  })
})